﻿using System;
using System.Text;

namespace Sustainalytics.ESGRatings.Primitives.Exceptions
{
    public class ESGException : Exception
    {
        public ESGException(string message) : base(message)
        {
        }


        public ESGException(int errorCode, string moduleName)
        {
            this.ErrorCode = errorCode;
            this.ModuleName = moduleName;
        }

        public ESGException(int errorCode, string errorMessage, string moduleName)
        {
            this.ErrorCode = errorCode;
            this.ModuleName = moduleName;
            this.InternalErrorMessage = errorMessage;
        }
        public ESGException(int errorCode, int internalErrorCode, string moduleName)
        {
            this.ErrorCode = errorCode;
            this.ModuleName = moduleName;
            this.InternalErrorCode = internalErrorCode;
        }

        public int ErrorCode
        {
            get;
            protected set;
        }

        public int InternalErrorCode
        {
            get;
            protected set;
        }

        public string ModuleName
        {
            get;
            protected set;
        }

        public string InternalErrorMessage { get; set; }
    
        public string File { get; set; }
        
        public string FunctionName { get; set; }

        public int LineNumber { get; set; }

        public override string Message
        {
            get
            {
                var builder = new StringBuilder(string.Format("Module = \"{0}\",  ErrorCode = {1}, InternalErrorCode = {2}, InternalErrorMessage = \"{3}\"",
                    ModuleName, ErrorCode, InternalErrorCode, InternalErrorMessage));
                if (!String.IsNullOrEmpty(File))
                {
                    builder.Append(", File :"); 
                    builder.Append(File); 
                }

                if (!String.IsNullOrEmpty(FunctionName))
                {
                    builder.Append(", FunctionName :");
                    builder.Append(FunctionName);
                }

                if (LineNumber > 0)
                {
                    builder.Append(", LineNumber :");
                    builder.Append(LineNumber);
                }


                return builder.ToString();
            }
        }
    }

}
